package ljl.codetop300;

public class _158_inven_mana {

  /**
   * 可以，但是不好，很笨，很晦涩
   */
  static class test {
    public int inventoryManagement(int[] stock) {
      int id = stock[0];
      int count = 1;
      for (int i = 1; i < stock.length; i++) {
        if (id != stock[i]) {
          if (count == 0) {
            count = 1;
            id = stock[i];
          } else {
            count--;
          }
        } else {
          count++;
        }
      }
      return id;
    }
  }

  static class lufei {
    public int inventoryManagement(int[] stock) {
      int num = 0, vote = 0;
      for (int i : stock) {
        if (vote == 0) num = i;
        vote += i == num ? 1 : -1;
      }
      return num;
    }
  }
}
